///////////////////////////////////////////////////////////////////////////////
// This file is taken directly from pyR, (C) Nial Peters 2011
//
// Copyright (C) Nial Peters 2012
//
// This file is part of AvoScan.
//
// AvoScan is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// AvoScan is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AvoScan.  If not, see <http://www.gnu.org/licenses/>.
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

#ifndef PYR_ERROR_H
#define PYR_ERROR_H

#ifdef PYTHON_BUILD
#include"Python.h"
#endif

#include<stdlib.h>
#include<stdio.h>


#define LOCATION "(%s:%d) ",__FILE__ ,__LINE__

enum pyr_err_type {NO_ERR=0, ERR=1, IO_ERR=2, VALUE_ERR=3, TYPE_ERR=4, RUN_ERR=5, MEM_ERR=6};

typedef struct Error{
	const char *message;
	enum pyr_err_type type;

} pyr_error_t;

extern pyr_error_t pyr_error;

#define FATAL(s) printf(LOCATION); printf("%s\n",s); exit(1)
#define WARN(s) printf(LOCATION); printf("%s\n",s)

#define RESET_ERR() pyr_error.type=NO_ERR
#define ERR_OCCURRED() ((int)pyr_error.type)

#define SET_ERR(m,t) pyr_error.message=m; pyr_error.type=t

#define GET_ERR_MES() pyr_error.message
#define GET_ERR_TYPE() ((int)pyr_error.type)

#ifdef PYTHON_BUILD
inline PyObject * GET_PYTHON_EXC(void);
#define RAISE_PYTHON_EXC() PyErr_SetString(GET_PYTHON_EXC(),GET_ERR_MES()); return NULL
#endif //PYTHON_H



#endif //PYR_ERROR_H
